<!doctype html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>登录</title>

    <link href="../static/css/login.css" th:href="@{/css/login.css}" rel="stylesheet">
</head>
<body>

<form id="loginForm" th:action="@{/login}" th:method="post">
    <div>
        <label for="username">账号:</label>
        <input type="text" id="username" name="username" value="admin">
    </div>
    <div>
        <label for="password">密码:</label>
        <input type="password" id="password" name="password" value="123456">
    </div>
    <button type="button" onclick="login()">登录</button>
</form>

</body>
<script src="../static/lib/jquery-3.4.0.js" th:src="@{/lib/jquery-3.4.0.js}"></script>
<script th:inline="javascript">
    function login() {
        var data = $('#loginForm').serialize();
        $.ajax({
            type: 'POST',
            url: './login',
            data: data,
            success: function (result) {
                if (result.status === 2000) {
                    window.location.href = './index';
                } else {
                    alert(result.message);
                }
            }
        })
    }
</script>
</html>
